<?php
namespace Wap\Controller;
class CustomAgreementController extends CommonController{
	
	// 合同详情
	public function detail(){
		$this->is_show_footer = 0;
		$agreement_id = $this->_get('agreement_id', '对不起，您的操作有误！');
		$info = D('CustomAgreement')->info($agreement_id);
		if(!$info){
			$this->error('找不到相关数据！');
		}
		$this->add_step($info['category_name']);
		$this->add_step($info['title']);
		// 更新查看人数
		D('CustomAgreement')->update_view_num($agreement_id);

		$where['agreement_id'] = $agreement_id;
		$list = D('Comment')->get_list($where, '', $this->_get('p', '', 1), $this->pagesize);
		//处理AJAX分页
		$this->page($list, D('Comment')->count);
		// 评价标签
		$comment_label = D('Comment')->get_comment_label($agreement_id);

		// 替换样式
		$search = array(
			"/style=\".*?\"/si",
			"/width=\".*?\"/si",
			"/height=\".*?\"/si",
		);
		$info['service_content'] = preg_replace($search, "", $info['service_content']);
		$info['why_select_milv'] = preg_replace($search, "", $info['why_select_milv']);

		$this->assign('list', $list);
		$this->assign('info', $info);
		$this->assign('comment_label', $comment_label);
		$this->display();
	}
	// 提交订单
	public function submit_order(){
		$agreement_id = $this->_get('agreement_id', '对不起，您的操作有误！');
		$user_id      = $this->user_id();
		if($this->is_lawyer){
			$this->error('对不起，您为律师用户，无法下单！');
		}
		if(IS_POST){
			$demand   = $this->_post('demand');
			$order_sn = D('Order')->submit($user_id, $agreement_id, $demand);
			if(!$order_sn){
				$this->error(D('Order')->tips_info);
			}
			$this->success('提交订单成功！', U('Order/pay', array('order_sn' => $order_sn)));
		}
		$info = D('CustomAgreement')->info($agreement_id);
		if(!$info){
			$this->error('找不到相关数据！');
		}
		$this->add_step($info['title']);

		$this->assign('info', $info);
		$this->display();
	}

}